﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Data;
using System.Collections;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.memorial_enum;
using AspNetCs.Enumerations.User_Enum;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;

public partial class Users_AncestralHallItemsList : BasePage
{
    protected int AncestralHallId = 0;
    private AncestralHallItemsBLL bll = new AncestralHallItemsBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/AncestralHallItemsList.aspx", "请您登录", true);
        
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Request["id"]))
            {
                ResultStr("Login.aspx", "参数错误");
            }
            else
            {
                ViewState["Id"] = Request["id"];
                this.AncestralHallId = StringHelper.isNumber_int(Request["id"]);
            }
            getMyCreateAncestralHallItems();
        }
        else
        {
            if (ViewState["Id"] != null)
            {
                this.AncestralHallId = StringHelper.isNumber_int(ViewState["Id"].ToString());
            }
        }
    }


    private void getMyCreateAncestralHallItems()
    {
        //Users_Model userModel = Base_GetUserInfo;
        //if (userModel.UserId <= 0)
        //{
        //    ResultStr("AncestralHallList.aspx", "无访问权限!");
        //}
        //else
        //{
        //    if (userModel.UserId != StringHelper.isNumber_int(dataTable.Rows[0]["CreateId"].ToString()))
        //    {
        //        ResultStr("AncestralHallList.aspx", "该祠堂不是您创建的，无访问权限!");
        //    }
        //}
        Users_Model userModel = Base_GetUserInfo;
        string propertyItems = "id,AncestralHallId,ItemName,CreateTime,IsSys";
        DataTable dataTable = bll.getAncestralHallItemsByAncestralHallId(this.AncestralHallId, propertyItems, 0);
        rptAnestralHallLItemsList.DataSource = dataTable;
        rptAnestralHallLItemsList.DataBind();
    }

    private bool deleteAncestralHallItems(int id)
    {

        //删除宗祠版块
        AncestralHallItemsBLL itemsBLL = new AncestralHallItemsBLL();
        int count = itemsBLL.DeleteById(id);

        return count > 0  ? true : false;
    }

    protected void rptAnestralHallLItemsList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        bool bo = false;
        //Response.Write("<script>alert('"+btnDelete.CommandArgument+"');</script>");
        if (e.CommandName == "delete")
        {
            Button btnDelete = e.Item.FindControl("btnDelete") as Button;
            if (btnDelete != null)
            {
                string id = btnDelete.CommandArgument;
                try
                {
                    bo = deleteAncestralHallItems(Convert.ToInt32(id));
                }
                catch (Exception ex)
                {
                    bo = false;
                }
            }
        }

        getMyCreateAncestralHallItems();
    }
}
